package com.changcheng.project.carinfo.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.changcheng.framework.aspectj.lang.annotation.Log;
import com.changcheng.framework.aspectj.lang.enums.BusinessType;
import com.changcheng.project.carinfo.domain.ACarInfo;
import com.changcheng.project.carinfo.service.IACarInfoService;
import com.changcheng.framework.web.controller.BaseController;
import com.changcheng.framework.web.domain.AjaxResult;
import com.changcheng.common.utils.poi.ExcelUtil;
import com.changcheng.framework.web.page.TableDataInfo;

/**
 * 车辆信息Controller
 * 
 * @author dazhi
 * @date 2020-11-02
 */
@Controller
@RequestMapping("/carinfo/carinfo")
public class ACarInfoController extends BaseController
{
    private String prefix = "carinfo/carinfo";

    @Autowired
    private IACarInfoService aCarInfoService;

    @RequiresPermissions("carinfo:carinfo:view")
    @GetMapping()
    public String carinfo()
    {
        return prefix + "/carinfo";
    }

    /**
     * 查询车辆信息列表
     */
    @RequiresPermissions("carinfo:carinfo:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ACarInfo aCarInfo)
    {
        startPage();
        List<ACarInfo> list = aCarInfoService.selectACarInfoList(aCarInfo);
        return getDataTable(list);
    }

    /**
     * 导出车辆信息列表
     */
    @RequiresPermissions("carinfo:carinfo:export")
    @Log(title = "车辆信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ACarInfo aCarInfo)
    {
        List<ACarInfo> list = aCarInfoService.selectACarInfoList(aCarInfo);
        ExcelUtil<ACarInfo> util = new ExcelUtil<ACarInfo>(ACarInfo.class);
        return util.exportExcel(list, "carinfo");
    }

    /**
     * 新增车辆信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存车辆信息
     */
    @RequiresPermissions("carinfo:carinfo:add")
    @Log(title = "车辆信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ACarInfo aCarInfo)
    {
        return toAjax(aCarInfoService.insertACarInfo(aCarInfo));
    }

    /**
     * 修改车辆信息
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        ACarInfo aCarInfo = aCarInfoService.selectACarInfoById(id);
        mmap.put("aCarInfo", aCarInfo);
        return prefix + "/edit";
    }

    /**
     * 修改保存车辆信息
     */
    @RequiresPermissions("carinfo:carinfo:edit")
    @Log(title = "车辆信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ACarInfo aCarInfo)
    {
        return toAjax(aCarInfoService.updateACarInfo(aCarInfo));
    }

    /**
     * 删除车辆信息
     */
    @RequiresPermissions("carinfo:carinfo:remove")
    @Log(title = "车辆信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(aCarInfoService.deleteACarInfoByIds(ids));
    }
}
